package com.firstjianmo.fragmentbestpractice.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.firstjianmo.fragmentbestpractice.R;
import com.firstjianmo.fragmentbestpractice.model.News;

import java.util.List;

/**
 * Created by pc on 2016/12/3.
 */

public class NewsAdapter extends ArrayAdapter<News> {

    private int resouceId;

    public NewsAdapter(Context context, int resouceId, List<News> objects) {
        super(context, resouceId, objects);
        this.resouceId = resouceId;
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        News news = getItem(position);
        View view;
        if (null == convertView) {
            view = LayoutInflater.from(getContext()).inflate(resouceId, null);
        } else {
            view = convertView;
        }
        TextView newsTitleText = (TextView) view.findViewById(R.id.news_title);
        newsTitleText.setText(news.getTitle());
        return view;
    }
}
